package com.example.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;

import androidx.appcompat.app.AppCompatActivity;

import com.example.demo.data.model.News;
import com.example.demo.data.model.NewsList;
import com.example.demo.databinding.ActivityNewsDetailBinding;

import java.util.stream.Collectors;

public class NewsDetailActivity extends AppCompatActivity {

    private ActivityNewsDetailBinding binding;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityNewsDetailBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        News news = NewsList.newsList.stream().filter(item -> item.getTitle().equals(title)).collect(Collectors.toList()).get(0);

        binding.newsDetailTitle.setText(title);
        binding.newsDetailContent.setText(Html.fromHtml(news.getContent(), Html.FROM_HTML_MODE_COMPACT));

        setJump();
    }

    private void setJump(){
        binding.jumpToAstro.setOnClickListener(view -> {
            startActivity(new Intent(this, AstroActivity.class));
        });
        binding.jumpToHis.setOnClickListener(view -> {
            startActivity(new Intent(this, DayInHistoryActivity.class));
        });
        binding.jumpToGold.setOnClickListener(view -> {
            startActivity(new Intent(this, GoldActivity.class));
        });
        binding.jumpToNews.setOnClickListener(view -> {
            startActivity(new Intent(this, NewsListActivity.class));
        });
        binding.jumpToPhone.setOnClickListener(view -> {
            startActivity(new Intent(this, PhoneActivity.class));
        });
    }

}